package cn.wqk.rrtf.service;

import cn.wqk.rrtf.mapper.RoleMapper;
import cn.wqk.rrtf.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleMapper roleMapper;
    @Override
    public Integer insertRole(Role role) throws DataAccessException {
            roleMapper.insertRole(role);
            Integer roleId=role.getRoleId();
            return roleId;
    }

    @Override
    public Integer updateRole(Role role) throws DataAccessException{
        roleMapper.updateRole(role);
        Integer roleId=role.getRoleId();
        return roleId;
    }

    @Override
    public Integer deleteRole(Role role) throws DataAccessException{
        roleMapper.deleteRole(1);
        Integer roleId=role.getRoleId();
        return roleId;
    }

    @Override
    public List<Role> selectAllRole(Role role) {
        List<Role> roleList =roleMapper.selectAllRole();
        for (Role role1 : roleList) {
            System.out.println(role1);
        }
        return roleList;
    }

    @Override
    public Role selectRoleByUserId(Integer userId) {
        Role roleList=roleMapper.selectRoleByUserId(1);
        System.out.println(roleList);
        return roleList;
    }

    @Override
    public Role selectRoleByCondition(Role role) {
        Role roleList=roleMapper.selectRoleByCondition(role);
        System.out.println(roleList);
        return roleList;
    }

}